package com.bit.blog.controller;

import com.bit.blog.pojo.request.AddBlogRequest;
import com.bit.blog.pojo.request.UpdateBlogRequest;
import com.bit.blog.pojo.response.BlogDetailResponse;
import com.bit.blog.pojo.response.BlogInfoResponse;
import com.bit.blog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource(name = "blogService")
    private BlogService blogService;

    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList(){
        return blogService.getList();
    }

    @RequestMapping("/getBlogDetail")
    public BlogDetailResponse getBlogDetail(@NotNull(message = "userId不能为空") Integer blogId){
        log.info("getBlogDetail方法，获取图书详情，blogId:{}", blogId);
        return blogService.getBlogDetail(blogId);
    }

    @RequestMapping("/addBlog")
    public Boolean addBlog(@Valid AddBlogRequest addBlogRequest){
        log.info("addBlog()添加博客，addBlogRequest:{}", addBlogRequest);
        return blogService.addBlog(addBlogRequest);
    }
    @RequestMapping("/updateBlog")
    public Boolean updateBlog(@RequestBody @Valid UpdateBlogRequest updateBlogRequest) {
        log.info("updateBlog()更新博客, updateBlogRequest:{}", updateBlogRequest);
        return blogService.updateBlog(updateBlogRequest);
    }

    @RequestMapping("/deleteBlog")
    public Boolean deleteBlog(Integer blogId){
        log.info("deleteBlog()删除博客，blogId:{}", blogId);
        return blogService.deleteBlog(blogId);
    }
}
